package com.example.system.controller;

import com.example.core.controller.BaseController;
import com.example.core.entity.PageDataInfo;
import com.example.core.result.Res;
import com.example.system.entity.DTO.ExamAddDTO;
import com.example.system.entity.DTO.ExamEditDTO;
import com.example.system.entity.DTO.ExamQueryDTO;
import com.example.system.entity.DTO.ExamQuestAddDTO;
import com.example.system.entity.VO.ExamDetailVO;
import com.example.system.entity.VO.ExamVO;
import com.example.system.service.IExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {
    @Autowired
    private IExamService examService;

    @GetMapping("/list")
    public PageDataInfo<ExamVO> list(ExamQueryDTO examQueryDTO) {
        return super.getPageDataInfo(examService.list(examQueryDTO));
    }

    @PostMapping("/add")
    public Res<String> add(@RequestBody ExamAddDTO examAddDTO) {
        return Res.ok(examService.add(examAddDTO));
    }

    @GetMapping("/detail")
    public Res<ExamDetailVO> detail(Long examId) {
        return Res.ok(examService.detail(examId));
    }

    @PostMapping("/edit")
    public Res<Void> edit(@RequestBody ExamEditDTO examEditDTO) {
        return super.toR(examService.edit(examEditDTO));
    }

    @DeleteMapping("/delete")
    public Res<Void> delete(Long examId) {
        return super.toR(examService.delete(examId));
    }

    @PutMapping("/publish")
    public Res<Void> publish(Long examId) {
        return super.toR(examService.publish(examId));
    }

    @PutMapping("/cancelPublish")
    public Res<Void> cancelPublish(Long examId) {
        return super.toR(examService.cancelPublish(examId));
    }

    @PostMapping("/question/add")
    public Res<Void> questionAdd(@RequestBody ExamQuestAddDTO examQuestAddDTO) {
        return super.toR(examService.questionAdd(examQuestAddDTO));
    }

    @DeleteMapping("/question/delete")
    public Res<Void> questionDelete(Long examId, Long questionId) {
        return toR(examService.questionDelete(examId, questionId));
    }

}
